package com.boot.util;

import lombok.extern.java.Log;
import org.springframework.context.MessageSource;
import org.springframework.context.NoSuchMessageException;
import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.stereotype.Component;

@Component
@Log
public class MessageUtil {

    public static String getMessage(String code, Object... args){
        try{
            MessageSource messageSource = SpringUtil.getBean(MessageSource.class);
            return messageSource.getMessage(code, args, LocaleContextHolder.getLocale());
        }catch (NoSuchMessageException e){
            log.warning(e.getMessage());
        }
        return code;
    }

}
